﻿using FluentFTP;
using SixLabors.ImageSharp.Metadata.Profiles.Xmp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace yingli_ningbo.Helpers
{
    public class FtpHelper
    {
        static public string path = System.Configuration.ConfigurationManager.AppSettings["file"];    //目标路径
        private FtpClient client;
        public FtpHelper(FtpClient client, string ftpip, bool isAnonymous = false, string username = "", string password = "")
        {
            this.client = client;

            // 根据是否匿名访问设置登录凭据
            var credentials = isAnonymous
                ? new NetworkCredential("anonymous", "")  // 匿名访问的用户名为 "anonymous"，密码为空或邮箱地址
                : new NetworkCredential(username, password);

            client.LoadProfile(new FtpProfile
            {
                Host = ftpip,
                Credentials = credentials,
                Encryption = FtpEncryptionMode.None,
                DataConnection = FtpDataConnectionType.AutoActive,
                Encoding = Encoding.UTF8,
                Timeout = 1000,
                SocketPollInterval = 1000,
                RetryAttempts = 5
            });

            client.Config.LogToConsole = false;
        }

    }
}
